﻿using Base.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Model
{
    [Serializable]
    public class member_expert
    {

        private readonly EFContext _context;
        public member_expert(EFContext context)
        {
            _context = context;
        }
        #region 
        /// <summary>
        /// id
        /// </summary>		
        public int id { get; set; }

        /// <summary>
        /// 是不是内部医生
        /// </summary>
        public bool IsInternal { get; set; }

        /// <summary>
        /// 专家图片 图像
        /// </summary>
        public string member_images { get; set; }

        /// <summary>
        /// 二维码
        /// </summary>
        public string member_qrcode { get; set; }

        /// <summary>
        /// 单位名称
        /// </summary>		
        public string hospital_name { get; set; }
        /// <summary>
        ///会员表ID
        /// </summary>		
        public int member_id { get; set; }
        /// <summary>
        /// 单位ID public_hospital表
        /// </summary>		
        public int hospital_id { get; set; }
        /// <summary>
        /// 个人简介
        /// </summary>		
        public string member_profile { get; set; }
        /// <summary>
        /// 医生科室
        /// </summary>		
        public int member_department { get; set; }

        /// <summary>
        /// 专家职称
        public string member_credentials { get; set; }

        /// <summary>
        /// 医生职称
        /// </summary>
        public int member_professor { get; set; }
        /// <summary>
        /// 医生擅长TAG{"tag_id":"标签ID","tag_name":"标签名称"}
        /// </summary>		
        public string member_tag { get; set; }
        /// <summary>
        /// 医生擅长知识模块{"channel_id":"频道ID","channel_name":"频道名称"}
        /// </summary>		
        public string member_channel { get; set; }
        /// <summary>
        /// 医生是否可直接在线咨询
        /// </summary>		
        public bool member_isonline { get; set; }
        /// <summary>
        /// 医生是否可接受预约，预约时间按排班表
        /// </summary>		
        public bool member_isappointment { get; set; }
        /// <summary>
        /// 医生是否可接受快速提问
        /// </summary>		
        public bool member_isquestion { get; set; }
        /// <summary>
        /// 评价得分 5分 每1小时更新一次 定时任务
        /// </summary>		
        public decimal member_evaluation_score { get; set; }
        /// <summary>
        /// 平均回复时间
        /// </summary>		
        public int member_reply_avgtime { get; set; }

        /// <summary>
        /// 是否为明星医生
        /// </summary>
        public string expert_tabids { get; set; }

        /// <summary>
        /// 关注用户数量
        /// </summary>
        public int member_liked { get; set; }

        /// <summary>
        /// 直播间id
        /// </summary>
        public int? live_id { get; set; }

        #endregion

        #region 帮助

        private bool GetExperFix(int MemberId, out DateTime StartTime, out DateTime EndTime)
        {
            StartTime = DateTime.Now;
            EndTime = DateTime.Now;
            //根据专家id判断专家是否是固定排班如果不是则不做任何操作，如果是则需要把时间替换成下次排班的固定时间
            fixed_scheduling f = _context.fixed_scheduling.FirstOrDefault(x => x.unionId == MemberId);
            if (object.Equals(f, null))
            {
                return false;
            }
            else
            {
                int nowWeek = (int)DateTime.Now.DayOfWeek;
                if (nowWeek == 0)
                {
                    nowWeek = 7;
                }
                int num = 0;
                if (nowWeek > f.week_one)//如果当前的星期，比专家的星期大，代表本周已经过了循环到下周的这个星期
                {
                    num = 7 - (nowWeek - f.week_one);

                }
                else//如果当前星期比专家的星期小说明是本周计算差几天就可以了
                {
                    num = f.week_one - nowWeek;
                }
                string date = DateTime.Now.AddDays(num).Date.ToString("yyyy-MM-dd");
                if (f.IsFirst)
                {
                    StartTime = Convert.ToDateTime(date + " 09:00:00");
                    EndTime = Convert.ToDateTime(date + " 12:00:00");
                }
                else
                {
                    StartTime = Convert.ToDateTime(date + " 14:30:00");
                    EndTime = Convert.ToDateTime(date + " 17:30:00");
                }
                return true;
            }



        }




        /// <summary>
        /// 获取专家状态
        /// </summary>
        /// <param name="start_time"></param>
        /// <param name="end_time"></param>
        /// <param name="isonline"></param>
        /// <param name="isappointment"></param>
        /// <returns></returns>
        public static int getExpertOnlineStatus(string start_time, string end_time, bool isonline, bool isappointment)
        {
            int status = (int)SystemEnum.EXPERONLINETSTATUS.离线;
            if (CString.IsEmpty(start_time) || CString.IsEmpty(end_time)) return status;

            if (DateTime.Now >= GetHelper.GetDateTime(start_time) && GetHelper.GetDateTime(end_time) > DateTime.Now && isonline) status = (int)SystemEnum.EXPERONLINETSTATUS.在线;
            if (DateTime.Now > GetHelper.GetDateTime(end_time) && isappointment) status = (int)SystemEnum.EXPERONLINETSTATUS.预约;
            return status;
        }
        #endregion

    }
}
